package com.aishua.aishuawallet.utils;

import android.graphics.Bitmap;
import android.graphics.BitmapShader;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.RectF;
import android.graphics.Shader;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.support.annotation.ColorInt;

/**
 * Created by aishua on 2018/8/1.
 */

public class BitmapUtils {

    public static Bitmap getNumberBitmap(int iconSize, String number, @ColorInt int background,@ColorInt int textColor) {
        return getNumberBitmap(iconSize, iconSize / 10, number,background,textColor);
    }

    public static Bitmap getNumberBitmap(int iconSize, int padding, String number,@ColorInt int background,@ColorInt int textColor) {
        Bitmap bitmap = Bitmap.createBitmap(iconSize, iconSize, Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(bitmap);
        RectF rect = new RectF(0, 0, canvas.getWidth(), canvas.getHeight());
        Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DEV_KERN_TEXT_FLAG);
        // draw background
//        paint.setColor(Color.WHITE);
//        canvas.drawOval(rect, paint);
        paint.setColor(background);
        canvas.drawOval(new RectF(padding, padding, rect.width() - padding, rect.height() - padding), paint);
        // draw text
        paint.setColor(textColor);
        paint.setStrokeWidth(3);
        paint.setTextSize(iconSize * 0.6f);
        paint.setTextAlign(Paint.Align.CENTER);
        Paint.FontMetricsInt fontMetrics = paint.getFontMetricsInt();
        float baseline = (rect.bottom + rect.top - fontMetrics.bottom - fontMetrics.top) / 2;
        canvas.drawText(number, rect.centerX(), baseline, paint);
        return bitmap;
    }


}
